<template>
  <div>
    <el-card class="roles_card">
      <div class="roles_outbox">
        <div class="roles_leftcard">
          <el-menu
            class="el-menu-vertical-demo"
            @select="activeMenuItem"
          >
            <el-menu-item v-for="ele in roleList" :key="ele.roleId" :index="''+ele.roleId">
              <i class="el-icon-user" />
              <span slot="title">{{ ele.roleName }}</span>
              <el-dropdown trigger="click">
                <span class="el-dropdown-link">
                  <i class="el-icon-arrow-down el-icon--right" />
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="$router.push(`/system/permissionEdit/${currentID}`)">编辑角色</el-dropdown-item>
                  <el-dropdown-item style="color:red" @click.native="del">删除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </el-menu-item>
          </el-menu>
          <el-button style="width:99%" @click="$router.push('/system/permission')">添加角色</el-button>
        </div>
        <div class="roles_rightcard">
          <div class="roles_top">
            <el-menu class="el-menu-demo" mode="horizontal">
              <el-menu-item index="1" @click="flag=false">功能权限</el-menu-item>
              <el-menu-item index="3" @click="flag=true">成员</el-menu-item>
            </el-menu>
          </div>
          <div v-show="flag===false" class="roles_context">
            <div class="roles_tree">
              <div class="roles_treetitle">
                园区管理
              </div>
              <el-tree ref="one" node-key="id" default-expand-all :expand-on-click-node="false" show-checkbox :data="parkingPermissionsList" :props="{label: 'title',disabled:dis}" />
            </div>
            <div class="roles_tree">
              <div class="roles_treetitle">
                行车管理
              </div>
              <el-tree ref="two" node-key="id" default-expand-all :expand-on-click-node="false" show-checkbox :data="carPermissionsList" :props="{label: 'title',disabled:dis}" />
            </div>
            <div class="roles_tree">
              <div class="roles_treetitle">
                物业费管理
              </div>
              <el-tree ref="three" node-key="id" default-expand-all :expand-on-click-node="false" show-checkbox :data="propertyPermissionsList" :props="{label: 'title',disabled:dis}" />
            </div>
            <div class="roles_tree">
              <div class="roles_treetitle">
                一体杆管理
              </div>
              <el-tree ref="four" node-key="id" default-expand-all :expand-on-click-node="false" show-checkbox :data="polePermissionsList" :props="{label: 'title',disabled:dis}" />
            </div>
            <div class="roles_tree">
              <div class="roles_treetitle">
                系统管理
              </div>
              <el-tree ref="five" node-key="id" default-expand-all :expand-on-click-node="false" show-checkbox :data="systemPermissionsList" :props="{label: 'title',disabled:dis}" />
            </div>
          </div>

          <div v-show="flag===true">
            <el-table
              v-loading="loading"
              :data="tableData"
            >
              <el-table-column
                type="index"
                label="序号"
                width="300"
              >
                <template #default="{$index}">
                  {{ $index+1 + pageSize *(page-1) }}
                </template>
              </el-table-column>

              <el-table-column width="400px" prop="name" label="员工姓名" />
              <el-table-column label="登陆账号" prop="userName" />
            </el-table>
            <el-pagination
              class="page"
              :current-page="page"
              :total="total"
              :page-size="pageSize"
              layout="total, prev, pager, next"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getRolesListAPI, roleSystemAPI, treeSystemAPI } from '@/api/system'
// import { getListRoleAPI } from '@/api/RoleManager'
export default {
  data() {
    return {
      page: 1,
      loading: false,
      pageSize: 10,
      // 定义成员列表
      tableData: [],
      // 展示隐藏
      flag: false,
      // 存储左边侧边栏数组
      roleList: [],
      // 右边
      parkingPermissionsList: [],
      carPermissionsList: [],
      propertyPermissionsList: [],
      polePermissionsList: [],
      systemPermissionsList: []
    }
  },
  created() {
    this.onRoleList()
  },
  methods: {
    async activeMenuItem(id) {
      console.log(id)
      // 成员
      const res2 = await getRolesListAPI(id)
      console.log(res2)
      this.tableData = res2.data
    },
    async onRoleList() {
      const res = await roleSystemAPI()
      const res1 = await treeSystemAPI()
      this.parkingPermissionsList.push(res1.data[0])
      this.carPermissionsList.push(res1.data[1])
      this.propertyPermissionsList.push(res1.data[2])
      this.polePermissionsList.push(res1.data[3])
      this.systemPermissionsList.push(res1.data[4])
      // console.log(res1)
      // console.log(res)
      this.roleList = res.data
    }
  }
}
</script>

<style lang="scss">
.page {
  float: right;
}
.roles_card{
  width: 98%;
  padding: 2px;
  margin-left: 1%;
  .roles_outbox{
    display: flex;
    width: 1215px;
    .roles_leftcard{
      padding: 0 10px;
      box-sizing: border-box;
      width: 18%;
    }
    .roles_rightcard{
      width: 82%;
      margin-left: 10px;
      .roles_top{
        height: 50px;
        background-color: #0861fc;
      }
      .roles_context{
        width: 1400px;
        height: 80vh;
        margin-top: 15px;
        display: flex;
        justify-content: space-between;
        .roles_tree{
          width: 20%;
          height: 400px;
          text-align: center;
          border-right: 1px solid #EEF0F3;
          &:last-child{
            border-right: none;
          }
          .roles_treetitle{
            display: flex;
            align-items: center;
            justify-content: center;
            width: 90%;
            height: 42px;
            background-color: #F5F7FA;
            margin: 10px auto;
          }
        }
      }
    }
  }

}

</style>
